package com.etone.smartAudit.controller;

import com.etone.smartAudit.dto.jiutian.TitlesDTO;

import com.etone.smartAudit.onlyoffice.util.JiuTianURLConstant;
import com.etone.smartAudit.service.JiuTianService;
import com.etone.smartAudit.vo.jiutian.CommonVO;
import com.etone.smartAudit.vo.jiutian.OcrPdfVO;
import com.etone.smartAudit.vo.jiutian.OcrWordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.io.*;
import java.util.*;

/**
 * <p>
 * 九天AI能力接口接入
 * </p>
 *
 * @author zhang
 * @since 2021-11-12
 */
@RestController
@Api(tags = "九天AI能力接口", value = "JiuTianAIController")
@Slf4j
public class JiuTianAIController {

    @Autowired
    private JiuTianService jiuTianService;

    @ApiOperation(value = "OCR通用文字识别接口(只支持jpg,PNG,jpeg格式)")
    @PostMapping("/jiutianAI/ocrWork")
    public Object ocrDiscernWork(@ApiParam(value = "图片", required = true) @RequestPart MultipartFile file) throws IOException {
        return jiuTianService.ocrDiscernWork(file);
    }

    @ApiOperation(value = "表格识别(返回html格式)")
    @PostMapping("/jiutianAI/sheetocr")
    public Object sheetocr(@ApiParam(value = "图片", required = true) @RequestPart MultipartFile file) throws IOException {
        return jiuTianService.sheetocr(file);
    }

    @ApiOperation(value = "文本关键字提取")
    @PostMapping("/jiutianAI/getKeywords")
    public Object getKeywords(@ApiParam(value = "文本内容", required = true) @RequestParam String text){
       return jiuTianService.getKeywords(text);
    }

    @ApiOperation(value = "命名实体类识别(可识别:人名，地名，机构名称等)")
    @PostMapping("/jiutianAI/bertner")
    public Object bertner(@ApiParam(value = "文本内容", required = true) @RequestParam String text){
        return jiuTianService.bertner(text);
    }

    @ApiOperation(value = "词相关服务(相关词，词向量获取，词义相似度)")
    @PostMapping("/jiutianAI/wordemy")
    public Object related(@ApiParam(value = "功能类型:(1、相关词,2、词义相似度,3、词向量获取)", required = true) @RequestParam Integer type,
                          @ApiParam(value = "关键词1", required = true) @RequestParam String word1,
                          @ApiParam(value = "关键词2") @RequestParam(required = false) String word2) {
       return jiuTianService.related(type, word1, word2);
    }


    @ApiOperation(value = "实体关系提取")
    @PostMapping("/jiutianAI/relationExtract")
    public Object relationExtract(@ApiParam(value = "文本内容", required = true) @RequestParam String text){
        return jiuTianService.relationExtract(text);
    }

    @ApiOperation(value = "多语言分词")
    @PostMapping("/jiutianAI/wordCut")
    public Object wordCut(@ApiParam(value = "文本内容", required = true) @RequestParam String word){
        return jiuTianService.wordCut(word);
    }


    @ApiOperation(value = "文本相似度识别")
    @PostMapping("/jiutianAI/titleSimilarity")
    public Object titleSimilarity(@ApiParam(value = "文本比较内容", required = true) @RequestBody List<TitlesDTO> titles) {
        return jiuTianService.titleSimilarity(titles);
    }

    @ApiOperation(value = "百度印章识别")
    @PostMapping("/jiutianAI/seal")
    public CommonVO<Object> seal(@ApiParam(value = "文件") @RequestPart(required = false) MultipartFile file,
                                 @ApiParam(value = "识别类型（1、图片,2、pdf,3、url）", required = true) @RequestParam Integer type,
                                 @ApiParam(value = "pdf检测页码") @RequestParam(required = false) Integer page,
                                 @ApiParam(value = "图片地址") @RequestParam(required = false) String urlAdd) {
        String url = JiuTianURLConstant.BAIDU_SEAL_URL;
        Object result = jiuTianService.baiduApi(file, type, page, urlAdd, url);
        return new CommonVO<>("200","success",result);
    }

    //百度OCR通用文字识别
    @ApiOperation(value = "百度OCR通用文字识别")
    @PostMapping("/jiutianAI/accurateBasic")
    public CommonVO<String> accurateBasic(@ApiParam(value = "文件") @RequestPart(required = false) MultipartFile file,
                                @ApiParam(value = "识别类型（1、图片,2、pdf,3、url）", required = true) @RequestParam Integer type,
                                @ApiParam(value = "pdf检测页码") @RequestParam(required = false) Integer page,
                                @ApiParam(value = "图片地址") @RequestParam(required = false) String urlAdd) {
       return jiuTianService.accurateBasic(file,type,page,urlAdd);
    }

    //识别全部PDF文件内容
    @ApiOperation(value = "百度PDF识别")
    @PostMapping("/jiutianAI/accurateBasicAll")
    public CommonVO<List<OcrPdfVO>> accurateBasicAll(@ApiParam(value = "文件") @RequestPart(required = false) MultipartFile file) {
        return jiuTianService.accurateBasicAll(file);
    }

    @PostMapping("/autoAudit/baiduWork")
    @ApiOperation(value = "百度表格识别")
    public CommonVO<List<OcrWordVO>> baiduWork(@ApiParam(value = "文件") @RequestPart("file") MultipartFile file) {
        return jiuTianService.baiduWork(file);
    }



}
